<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h2 class="title">Hello world</h2>
  <button class="btn">改变文本</button>
  <button class="btn" onclick="changeH2">改变文本</button>

  <script>
    // 命令式编程：每做一个操作，都是给计算机（浏览器）一步步命令
    // 声明式编程
    // 1、定义数据
    let message = "Hello world"

    // 2、将数据显示在h2元素中
    const titleEl = document.getElementsByClassName('title')[0]
    titleEl.innerHTML = message

    // 3、点击按钮，界面数据发生改变
    const btnEl = document.getElementsByClassName('btn')[0]
    btnEl.addEventListener('click', () => {
      titleEl.innerHTML = '你好'
    })
    const btnEl2 = document.getElementsByClassName('btn')[1]
    btnEl2.onclick = function(){
      titleEl.innerHTML = '你好2'
    }
  </script>
</body>
</html>